package com.gitee.wsl.prism4j.languages

import com.gitee.wsl.prism4j.Prism4j
import com.gitee.wsl.prism4j.Prism4j.Companion.grammar
import com.gitee.wsl.prism4j.Prism4j.Companion.pattern
import com.gitee.wsl.prism4j.Prism4j.Companion.token
import com.gitee.wsl.prism4j.annotations.Aliases
import com.gitee.wsl.prism4j.Prism4j.Pattern

@Suppress("unused")
@Aliases("jsonp")
object Prism_json {
    fun create(prism4j: Prism4j): Prism4j.Grammar {
        return grammar(
            "json",
            token(
                "property",
                pattern(Pattern.compile("\"(?:\\\\.|[^\\\\\"\\r\\n])*\"(?=\\s*:)", Pattern.CASE_INSENSITIVE))
            ),
            token("string", pattern(Pattern.compile("\"(?:\\\\.|[^\\\\\"\\r\\n])*\"(?!\\s*:)"), false, true)),
            token(
                "number",
                pattern(Pattern.compile("\\b0x[\\dA-Fa-f]+\\b|(?:\\b\\d+\\.?\\d*|\\B\\.\\d+)(?:[Ee][+-]?\\d+)?"))
            ),
            token("punctuation", pattern(Pattern.compile("[{}\\[\\]);,]"))),  // not sure about this one...
            token("operator", pattern(Pattern.compile(":"))),
            token("boolean", pattern(Pattern.compile("\\b(?:true|false)\\b", Pattern.CASE_INSENSITIVE))),
            token("null", pattern(Pattern.compile("\\bnull\\b", Pattern.CASE_INSENSITIVE)))
        )
    }
}
